using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Admin_Admin_Stock_StockOutManage : Admin, IRequiresSessionState
{
	private string linkHead = "";
	private string beforeUrl = "Admin_Stock_StockOutManage.aspx?MenuID=5&MenuName=库存管理&FileName=缺货登记管理";
	protected ScriptManager ScriptManager1;
	protected Literal ltrTitle;
	protected HtmlTable table_item;
	protected DropDownList ddlDetailSearchType;
	protected TextBox DetailSearchName;
	protected DropDownList ddlProdcutType;
	protected Button SeachBut;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected UpdatePanel UpdatePanel1;
	protected Panel phManage;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			if (!base.admin.CheckAdminPower(45))
			{
				base.WriteLog("Modidy", Language.GetAdminMsg("Log/Access", "0"), "Admin_Stock_StockOutManage");
				base.WriteRightErrMsg();
			}
			this.BindOutStockLog();
		}
	}
	protected void BindOutStockLog()
	{
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HLShop_Product p,HL_OutStockLog s where p.ProductID=s.ProductID and p.EnableSingleSell=1 and p.EnableSale=1 and p.IsDeleted=0 ";
		int pageSize = this.gvManage.PageSize;
		int listCount = BLLInstance.BllClientByPage.GetListCount("select count(*)" + text + query);
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,p.ProductName,p.ProductType,p.ProductSmallImageUrl,(select UserName from HL_User where UserID=s.UserID) as UserName,(select UserName from HL_User where UserID=p.SalerID) as SalerName,s.* ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = BLLInstance.BllClientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		string url = this.beforeUrl + this.linkHead + "&pageindex";
		string text2 = CurrPageLinks.instance.CurrPageLinkStr(num, pageSize, listCount, "条记录&nbsp;&nbsp;每页" + pageSize + "&nbsp;&nbsp;记录", url);
		string text3 = "";
		if (!string.IsNullOrEmpty(text2))
		{
			text3 = "<div class=\"page\">" + text2 + "</div>";
		}
		this.ltrPagePanel.Text = text3;
		for (int i = 0; i < this.gvManage.Rows.Count; i++)
		{
			HiddenField hiddenField = (HiddenField)this.gvManage.Rows[i].FindControl("hfEmail");
			HiddenField hiddenField2 = (HiddenField)this.gvManage.Rows[i].FindControl("hfMobile");
			Image image = (Image)this.gvManage.Rows[i].FindControl("imgEmail");
			Image image2 = (Image)this.gvManage.Rows[i].FindControl("imgMobile");
			if (hiddenField != null)
			{
				if (hiddenField.Value.ToLower() == "true")
				{
					image.ImageUrl = "~/Images/Client/mail.gif";
				}
				if (hiddenField2.Value.ToLower() == "true")
				{
					image2.ImageUrl = "~/Images/Client/phone.gif";
				}
			}
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ProductType");
		if (!string.IsNullOrEmpty(text2))
		{
			this.ddlProdcutType.ddlSelect(text2);
		}
		else
		{
			text2 = this.ddlProdcutType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2) && text2 != "0")
		{
			text = text + " and p.ProductType=" + text2;
			this.linkHead = this.linkHead + "&ProductType=" + text2;
		}
		string text3 = Fetch.Get("DetailSearch");
		if (!string.IsNullOrEmpty(text3))
		{
			this.ddlDetailSearchType.ddlSelect(text3);
		}
		else
		{
			text3 = this.ddlDetailSearchType.SelectedValue;
		}
		string text4 = Fetch.Get("DetailSearchName");
		if (!string.IsNullOrEmpty(text4))
		{
			this.DetailSearchName.Text = text4;
		}
		else
		{
			text4 = this.DetailSearchName.Text;
		}
		if (!string.IsNullOrEmpty(text4) && !string.IsNullOrEmpty(text3))
		{
			string text5 = text3;
			if (text5 != null)
			{
				if (!(text5 == "product_name"))
				{
					if (text5 == "saler_name")
					{
						text = text + "and SalerID in(Select UserID From [HL_User] Where UserName like '%" + text4 + "%')";
					}
				}
				else
				{
					text = text + "and ProductName like '%" + text4 + "%'";
				}
			}
			string text6 = this.linkHead;
			this.linkHead = string.Concat(new string[]
			{
				text6,
				"&DetailSearch=",
				text3,
				"&DetailSearchName=",
				base.Server.UrlEncode(text4)
			});
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by s.OutStockLogID desc";
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindOutStockLog();
	}
	protected string GetStatus(object value)
	{
		string result = value.ToString();
		if (value.ToString().ToLower().Trim() == "0")
		{
			result = "<span style='color:Red; font-size:12px;'>×</span>";
		}
		else
		{
			if (value.ToString().ToLower().Trim() == "1")
			{
				result = "<span style='color:Green; font-size:12px;'>√</span>";
			}
		}
		return result;
	}
	protected string GetContacPhone(string email, string mobile)
	{
		string text = "";
		if (!string.IsNullOrEmpty(email))
		{
			text = text + "<span style='color:Red; font-size:12px;'>&nbsp;Email：</span>" + email + "<br>";
		}
		if (!string.IsNullOrEmpty(mobile))
		{
			text = text + "<span style='color:Red; font-size:12px;'>&nbsp;手 机：</span>" + mobile;
		}
		return text;
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindOutStockLog();
	}
}
